package com.easepal802s.project.ui.presenter;


import android.util.Log;

import com.ogawa.base.Constant.BleConstant;
import com.easepal802s.project.ble.BleController;
import com.easepal802s.project.ble.HexUtils;
import com.easepal802s.project.ui.iview.IScanShoulderView;


/**
 * 肩部检测
 * Created by FHB on 2017/12/13.
 */

public class ScanShoulderPresenter extends MBasePresenter {
    IScanShoulderView mView;
    public static final int SCANNING =-1;
    public static final int SCAN_COMPLETE = 5;

    private static int SCAN_STATE;
    private static boolean IS_CAN_ADJUST;
    private byte mByteData ;
    public ScanShoulderPresenter(IScanShoulderView view) {
        mView = view;
    }

    public int getScanstate(){
        return SCAN_STATE;
    }
    public boolean getIsCan(){
        return IS_CAN_ADJUST;
    }



    @Override
    public void getDatas(String data) {
        synchronized (this) {
            if (data.startsWith(BleConstant.BAG1_HEAD)) {
                byte[] buffer = HexUtils.hexToByte(data);
                byte byte4 =  buffer[4];
                if (mByteData!=byte4) {
                    mByteData = byte4;
                    if (HexUtils.getByteInPosition(data, 4, 6).equals("1")) {
                        IS_CAN_ADJUST = true;
                        BleController.getInst().setIsCanAdjust(true);
                        mView.startToActivity();
                        return;
                    } else {
                        IS_CAN_ADJUST = false;
                        BleController.getInst().setIsCanAdjust(false);


                    }

                    if (HexUtils.getByteInPosition(data, 4, 5).equals("1")) {
                        Log.e("SCAN_STATE","OK");
                        SCAN_STATE = SCAN_COMPLETE;
                        BleController.getInst().setIsScanning(false);
                        mView.startToActivity();
                    }

                    else {
                        Log.e("SCAN_STATE","ING");
                        BleController.getInst().setIsScanning(true);
                        SCAN_STATE = SCANNING;
                    }


                }

            }
        }




    }



}
